clear all
use "Undirected Dyad example file.dta", replace


* Create undirected dyad contagion spatial lag variable with (undirected) contiguity variable of form ik*jm as connectivity variable
* Note: ik*jm means that for other dyads to matter, both countries k and m must be contiguous to both i and j (complementary contiguity)
* The created spatial effect variable has no values for country_i=="Japan" since Japan has no contiguous neighbor in this dataset
spundir  BIT, weight(contig_or_less1000km) i(country_i) j(country_j) time(year) link(ik*jm) sename(SL_undir_W_contig_compl) filename(SL_undir_W_contig_compl)

* As above, but (undirected) contiguity variable of form ik+jm as connectivity variable (substitutable contiguity)
* Note: ik+jm means that for other dyads to matter, it is sufficient if either country k or m is contiguous to i or j
spundir  BIT, weight(contig_or_less1000km) i(country_i) j(country_j) time(year) link(ik+jm) sename(SL_undir_W_contig_subst) filename(SL_undir_W_contig_subst)


* As above, but excluding dyads that contain either i or j from exerting a spatial effect
spundir  BIT, weight(contig_or_less1000km) i(country_i) j(country_j) time(year) link(ik+jm) exclusive sename(SL_undirexcl_W_contig_subst) filename(SL_undirexcl_W_contig_subst)

* Create undirected dyad contagion spatial lag variable with directed exports from i to k as connectivity variable
spundir  BIT, weight(exports_i_to_j) i(country_i) j(country_j) time(year) link(ik) sename(SL_undir_W_exports_i_to_k) filename(SL_undir_W_exports_i_to_k)


* Create undirected dyad contagion spatial lag variable with directed exports from k to i as connectivity variable
spundir  BIT, weight(exports_i_to_j) i(country_i) j(country_j) time(year) link(ki) sename(SL_undir_W_exports_k_to_i) filename(SL_undir_W_exports_k_to_i) 


